home *** CD-ROM | disk | FTP | other *** search
/ C# & Game Programming - A…er's Guide (2nd Edition) / Buono 2nd Ed.iso / Chapter2 / 2.16 / 2.16.cs next >
Encoding:
Text File  |  2004-10-19  |  3.4 KB  |  76 lines

  1. /* Battle Bit: The Text Adventure 
  2.  * You're a lieutenant in earth's toughest military fleet. Your 
  3.  * current mission is to guard earth's intergalactic conference hall. */
  4. using System;
  5.  
  6. namespace Chapter2 {
  7.     class Class1 {
  8.         static void Main() {
  9.             string input;
  10.             int iAmmo = 12, // player has 12 guesses
  11.                 iAlienShip = 49, // the alien ship starts here 
  12.                 iTarget = 50;   // This variable stores your input  
  13.  
  14.             /* Game introduction - explains to the player what he needs to
  15.              * do, why he is doing it.  The introduction should also, be 
  16.              * used to set the games mood and excite the player. */
  17.  
  18.             Console.WriteLine("\n Captain, aliens are attempting "
  19.                 + "to land peacefully!\n" 
  20.                 + "What? How dare they and on the day we're suppose "
  21.                 + "to start peace talks.\n" 
  22.                 + "It just goes to show you, you just can't trust "
  23.                 + "those alien scum.\n"
  24.                 + "Lieutenant, lock target, I don't want to see one "
  25.                 + "alien left alive.\n"
  26.                 + "But captain, isn't that the ambassadors ship!\n"
  27.                 + "And wasn't he suppose to be coming today?\n"
  28.                 + "Lieutenant, are you going to target the alien "
  29.                 + "ship or not?\n"
  30.                 + "But sir. \n Type in the ships location and fire soldier!\n" 
  31.                 + "But sir!\n" 
  32.                 + "Lieutenant, you'll take out that alien scum or I'll "
  33.                 + "take you out!\n"
  34.                 + "(The captains gun points oddly at your head.) " 
  35.                 + "Got it? Yes sir!\n");
  36.  
  37.             // location of ship û this just makes it harder to find the ship     
  38.             iAlienShip = ((iAlienShip * iAmmo) / (iTarget + 1)) + 3;  
  39.   
  40.             while (iAmmo > 0) {  // when ammo runs out the loop ends
  41.                 Console.WriteLine("\n\n Enter targeting information?");     
  42.                 input = Console.ReadLine();
  43.                 iTarget = int.Parse(input);
  44.     
  45.                 if (iTarget == iAlienShip) {  
  46.                     // if your input equals the ships location
  47.                     Console.WriteLine("Alien ship hit, the ships been destroyed sir.");
  48.                     break; // break ends loop 
  49.                 } else if (iTarget > iAlienShip) {  
  50.                     // when input is too high
  51.                     Console.WriteLine("You missed, try aiming a little lower");
  52.                     iAmmo--; // ammoùreduces the total ammo by 1
  53.                 } else { 
  54.                     // when input is to low 
  55.                     Console.WriteLine("You missed, try aiming higher");
  56.                     iAmmo--; // also reduces ammo by 1 
  57.                 }
  58.  
  59.                 // The location of the ship moves with each shot     
  60.                 if (iTarget == 0) {
  61.                   iTarget = 1;
  62.                 }
  63.                 iAlienShip = (iAlienShip * iAmmo) / iTarget;
  64.             }                    
  65.     
  66.             if (iAmmo > 0) // if you have ammo you must have hit the alien
  67.                 Console.WriteLine("\n Good work soldier, remind me to promote you.");
  68.             else // if your out of ammo you can't protect the hall
  69.                 Console.WriteLine("\n BOOM!!! You're dead.\n");         
  70.     
  71.             Console.WriteLine ("\n Game Over\n");
  72.         } 
  73.     }
  74. }
  75.  
  76.